import os

from celery import Celery
from celery.schedules import crontab

from medtime.settings import CELERY_BROKER_URL
from medtime.settings import CELERY_NAMESPACE
from medtime.settings import PROJECT_NAME

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'medtime.settings')
app = Celery(
    PROJECT_NAME, broker=CELERY_BROKER_URL,
    include=['service.tasks'], )

app.config_from_object('django.conf:settings', namespace=CELERY_NAMESPACE)

app.conf.beat_schedule = {
    'create-months-task': {
        'task': 'service.tasks.create_months_task',
        'schedule': crontab(minute=1, hour=0, day_of_month=1, month_of_year=1),
    },
}

app.autodiscover_tasks()
